package com.kfm.base.function2;

import java.util.Arrays;

public class Demo04 {

    public static void main(String[] args) {
        /*
        编写一个程序，生成一个给指行数的杨辉三角存储在二维数组并输出
         */

        int n = 5;

        int[][] arr = triangle(n);

        for (int i = 0; i < arr.length; i++) {
            System.out.println(Arrays.toString(arr[i]));
        }
    }

    public static int[][] triangle(int row){
        int[][] triangle = new int[row][];

        for (int i = 0; i < triangle.length; i++) {
            triangle[i] = new int[i + 1];
            triangle[i][0] = 1; // 第一个
            triangle[i][i] = 1; // 最后一个
            for (int j = 1; j < i ; j++) {
                triangle[i][j] = triangle[i - 1][j] + triangle[i -1][j - 1];
            }
        }

        return triangle;
    }
}
